/**
 */
package org.mro.grib.model.files.secondEdition.impl;

import java.nio.ByteBuffer;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import org.mro.grib.core.MessageException;
import org.mro.grib.core.SectionException;
import org.mro.grib.model.files.secondEdition.Message;
import org.mro.grib.model.files.secondEdition.SecondEditionPackage;
import org.mro.grib.model.files.secondEdition.sections.BitMapSection;
import org.mro.grib.model.files.secondEdition.sections.DataRepresentationSection;
import org.mro.grib.model.files.secondEdition.sections.DataSection;
import org.mro.grib.model.files.secondEdition.sections.GridDefinitionSection;
import org.mro.grib.model.files.secondEdition.sections.IdentificationSection;
import org.mro.grib.model.files.secondEdition.sections.IndicatorSection;
import org.mro.grib.model.files.secondEdition.sections.LocalUseSection;
import org.mro.grib.model.files.secondEdition.sections.ProductDefinitionSection;
import org.mro.grib.model.files.secondEdition.sections.SectionsFactory;
import org.mro.grib.model.files.secondEdition.sections.SectionsPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Message</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getStartOffset <em>Start Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getEndOffset <em>End Offset</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getIndicatorSection <em>Indicator Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getIdentificationSection <em>Identification Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getLocalUseSection <em>Local Use Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getGridDefinitionSection <em>Grid Definition Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getProductDefinitionSection <em>Product Definition Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getDataRepresentationSection <em>Data Representation Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getBitMapSection <em>Bit Map Section</em>}</li>
 *   <li>{@link org.mro.grib.model.files.secondEdition.impl.MessageImpl#getDataSection <em>Data Section</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MessageImpl extends EObjectImpl implements Message {
	/**
	 * The default value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long START_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getStartOffset() <em>Start Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getStartOffset()
	 * @generated
	 * @ordered
	 */
	protected long startOffset = START_OFFSET_EDEFAULT;

	/**
	 * The default value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected static final long END_OFFSET_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getEndOffset() <em>End Offset</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getEndOffset()
	 * @generated
	 * @ordered
	 */
	protected long endOffset = END_OFFSET_EDEFAULT;

	/**
	 * The cached value of the '{@link #getIndicatorSection() <em>Indicator Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIndicatorSection()
	 * @generated
	 * @ordered
	 */
	protected IndicatorSection indicatorSection;

	/**
	 * The cached value of the '{@link #getIdentificationSection() <em>Identification Section</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getIdentificationSection()
	 * @generated
	 * @ordered
	 */
	protected IdentificationSection identificationSection;

	/**
	 * The cached value of the '{@link #getLocalUseSection() <em>Local Use Section</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocalUseSection()
	 * @generated
	 * @ordered
	 */
	protected EList<LocalUseSection> localUseSection;

	/**
	 * The cached value of the '{@link #getGridDefinitionSection() <em>Grid Definition Section</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getGridDefinitionSection()
	 * @generated
	 * @ordered
	 */
	protected EList<GridDefinitionSection> gridDefinitionSection;

	/**
	 * The cached value of the '{@link #getProductDefinitionSection() <em>Product Definition Section</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getProductDefinitionSection()
	 * @generated
	 * @ordered
	 */
	protected EList<ProductDefinitionSection> productDefinitionSection;

	/**
	 * The cached value of the '{@link #getDataRepresentationSection() <em>Data Representation Section</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataRepresentationSection()
	 * @generated
	 * @ordered
	 */
	protected EList<DataRepresentationSection> dataRepresentationSection;

	/**
	 * The cached value of the '{@link #getBitMapSection() <em>Bit Map Section</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBitMapSection()
	 * @generated
	 * @ordered
	 */
	protected EList<BitMapSection> bitMapSection;

	/**
	 * The cached value of the '{@link #getDataSection() <em>Data Section</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDataSection()
	 * @generated
	 * @ordered
	 */
	protected EList<DataSection> dataSection;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MessageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SecondEditionPackage.Literals.MESSAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getStartOffset() {
		return startOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setStartOffset(long newStartOffset) {
		long oldStartOffset = startOffset;
		startOffset = newStartOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SecondEditionPackage.MESSAGE__START_OFFSET, oldStartOffset, startOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getEndOffset() {
		return endOffset;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setEndOffset(long newEndOffset) {
		long oldEndOffset = endOffset;
		endOffset = newEndOffset;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SecondEditionPackage.MESSAGE__END_OFFSET, oldEndOffset, endOffset));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IndicatorSection getIndicatorSection() {
		return indicatorSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetIndicatorSection(IndicatorSection newIndicatorSection, NotificationChain msgs) {
		IndicatorSection oldIndicatorSection = indicatorSection;
		indicatorSection = newIndicatorSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SecondEditionPackage.MESSAGE__INDICATOR_SECTION, oldIndicatorSection, newIndicatorSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIndicatorSection(IndicatorSection newIndicatorSection) {
		if (newIndicatorSection != indicatorSection) {
			NotificationChain msgs = null;
			if (indicatorSection != null)
				msgs = ((InternalEObject)indicatorSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SecondEditionPackage.MESSAGE__INDICATOR_SECTION, null, msgs);
			if (newIndicatorSection != null)
				msgs = ((InternalEObject)newIndicatorSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SecondEditionPackage.MESSAGE__INDICATOR_SECTION, null, msgs);
			msgs = basicSetIndicatorSection(newIndicatorSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SecondEditionPackage.MESSAGE__INDICATOR_SECTION, newIndicatorSection, newIndicatorSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public IdentificationSection getIdentificationSection() {
		return identificationSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetIdentificationSection(IdentificationSection newIdentificationSection, NotificationChain msgs) {
		IdentificationSection oldIdentificationSection = identificationSection;
		identificationSection = newIdentificationSection;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION, oldIdentificationSection, newIdentificationSection);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setIdentificationSection(IdentificationSection newIdentificationSection) {
		if (newIdentificationSection != identificationSection) {
			NotificationChain msgs = null;
			if (identificationSection != null)
				msgs = ((InternalEObject)identificationSection).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION, null, msgs);
			if (newIdentificationSection != null)
				msgs = ((InternalEObject)newIdentificationSection).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION, null, msgs);
			msgs = basicSetIdentificationSection(newIdentificationSection, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION, newIdentificationSection, newIdentificationSection));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LocalUseSection> getLocalUseSection() {
		if (localUseSection == null) {
			localUseSection = new EObjectContainmentEList<LocalUseSection>(LocalUseSection.class, this, SecondEditionPackage.MESSAGE__LOCAL_USE_SECTION);
		}
		return localUseSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<GridDefinitionSection> getGridDefinitionSection() {
		if (gridDefinitionSection == null) {
			gridDefinitionSection = new EObjectContainmentEList<GridDefinitionSection>(GridDefinitionSection.class, this, SecondEditionPackage.MESSAGE__GRID_DEFINITION_SECTION);
		}
		return gridDefinitionSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<ProductDefinitionSection> getProductDefinitionSection() {
		if (productDefinitionSection == null) {
			productDefinitionSection = new EObjectContainmentEList<ProductDefinitionSection>(ProductDefinitionSection.class, this, SecondEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION);
		}
		return productDefinitionSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DataRepresentationSection> getDataRepresentationSection() {
		if (dataRepresentationSection == null) {
			dataRepresentationSection = new EObjectContainmentEList<DataRepresentationSection>(DataRepresentationSection.class, this, SecondEditionPackage.MESSAGE__DATA_REPRESENTATION_SECTION);
		}
		return dataRepresentationSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BitMapSection> getBitMapSection() {
		if (bitMapSection == null) {
			bitMapSection = new EObjectContainmentEList<BitMapSection>(BitMapSection.class, this, SecondEditionPackage.MESSAGE__BIT_MAP_SECTION);
		}
		return bitMapSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DataSection> getDataSection() {
		if (dataSection == null) {
			dataSection = new EObjectContainmentEList<DataSection>(DataSection.class, this, SecondEditionPackage.MESSAGE__DATA_SECTION);
		}
		return dataSection;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case SecondEditionPackage.MESSAGE__INDICATOR_SECTION:
				return basicSetIndicatorSection(null, msgs);
			case SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION:
				return basicSetIdentificationSection(null, msgs);
			case SecondEditionPackage.MESSAGE__LOCAL_USE_SECTION:
				return ((InternalEList<?>)getLocalUseSection()).basicRemove(otherEnd, msgs);
			case SecondEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				return ((InternalEList<?>)getGridDefinitionSection()).basicRemove(otherEnd, msgs);
			case SecondEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				return ((InternalEList<?>)getProductDefinitionSection()).basicRemove(otherEnd, msgs);
			case SecondEditionPackage.MESSAGE__DATA_REPRESENTATION_SECTION:
				return ((InternalEList<?>)getDataRepresentationSection()).basicRemove(otherEnd, msgs);
			case SecondEditionPackage.MESSAGE__BIT_MAP_SECTION:
				return ((InternalEList<?>)getBitMapSection()).basicRemove(otherEnd, msgs);
			case SecondEditionPackage.MESSAGE__DATA_SECTION:
				return ((InternalEList<?>)getDataSection()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SecondEditionPackage.MESSAGE__START_OFFSET:
				return getStartOffset();
			case SecondEditionPackage.MESSAGE__END_OFFSET:
				return getEndOffset();
			case SecondEditionPackage.MESSAGE__INDICATOR_SECTION:
				return getIndicatorSection();
			case SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION:
				return getIdentificationSection();
			case SecondEditionPackage.MESSAGE__LOCAL_USE_SECTION:
				return getLocalUseSection();
			case SecondEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				return getGridDefinitionSection();
			case SecondEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				return getProductDefinitionSection();
			case SecondEditionPackage.MESSAGE__DATA_REPRESENTATION_SECTION:
				return getDataRepresentationSection();
			case SecondEditionPackage.MESSAGE__BIT_MAP_SECTION:
				return getBitMapSection();
			case SecondEditionPackage.MESSAGE__DATA_SECTION:
				return getDataSection();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SecondEditionPackage.MESSAGE__START_OFFSET:
				setStartOffset((Long)newValue);
				return;
			case SecondEditionPackage.MESSAGE__END_OFFSET:
				setEndOffset((Long)newValue);
				return;
			case SecondEditionPackage.MESSAGE__INDICATOR_SECTION:
				setIndicatorSection((IndicatorSection)newValue);
				return;
			case SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION:
				setIdentificationSection((IdentificationSection)newValue);
				return;
			case SecondEditionPackage.MESSAGE__LOCAL_USE_SECTION:
				getLocalUseSection().clear();
				getLocalUseSection().addAll((Collection<? extends LocalUseSection>)newValue);
				return;
			case SecondEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				getGridDefinitionSection().clear();
				getGridDefinitionSection().addAll((Collection<? extends GridDefinitionSection>)newValue);
				return;
			case SecondEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				getProductDefinitionSection().clear();
				getProductDefinitionSection().addAll((Collection<? extends ProductDefinitionSection>)newValue);
				return;
			case SecondEditionPackage.MESSAGE__DATA_REPRESENTATION_SECTION:
				getDataRepresentationSection().clear();
				getDataRepresentationSection().addAll((Collection<? extends DataRepresentationSection>)newValue);
				return;
			case SecondEditionPackage.MESSAGE__BIT_MAP_SECTION:
				getBitMapSection().clear();
				getBitMapSection().addAll((Collection<? extends BitMapSection>)newValue);
				return;
			case SecondEditionPackage.MESSAGE__DATA_SECTION:
				getDataSection().clear();
				getDataSection().addAll((Collection<? extends DataSection>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SecondEditionPackage.MESSAGE__START_OFFSET:
				setStartOffset(START_OFFSET_EDEFAULT);
				return;
			case SecondEditionPackage.MESSAGE__END_OFFSET:
				setEndOffset(END_OFFSET_EDEFAULT);
				return;
			case SecondEditionPackage.MESSAGE__INDICATOR_SECTION:
				setIndicatorSection((IndicatorSection)null);
				return;
			case SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION:
				setIdentificationSection((IdentificationSection)null);
				return;
			case SecondEditionPackage.MESSAGE__LOCAL_USE_SECTION:
				getLocalUseSection().clear();
				return;
			case SecondEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				getGridDefinitionSection().clear();
				return;
			case SecondEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				getProductDefinitionSection().clear();
				return;
			case SecondEditionPackage.MESSAGE__DATA_REPRESENTATION_SECTION:
				getDataRepresentationSection().clear();
				return;
			case SecondEditionPackage.MESSAGE__BIT_MAP_SECTION:
				getBitMapSection().clear();
				return;
			case SecondEditionPackage.MESSAGE__DATA_SECTION:
				getDataSection().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SecondEditionPackage.MESSAGE__START_OFFSET:
				return startOffset != START_OFFSET_EDEFAULT;
			case SecondEditionPackage.MESSAGE__END_OFFSET:
				return endOffset != END_OFFSET_EDEFAULT;
			case SecondEditionPackage.MESSAGE__INDICATOR_SECTION:
				return indicatorSection != null;
			case SecondEditionPackage.MESSAGE__IDENTIFICATION_SECTION:
				return identificationSection != null;
			case SecondEditionPackage.MESSAGE__LOCAL_USE_SECTION:
				return localUseSection != null && !localUseSection.isEmpty();
			case SecondEditionPackage.MESSAGE__GRID_DEFINITION_SECTION:
				return gridDefinitionSection != null && !gridDefinitionSection.isEmpty();
			case SecondEditionPackage.MESSAGE__PRODUCT_DEFINITION_SECTION:
				return productDefinitionSection != null && !productDefinitionSection.isEmpty();
			case SecondEditionPackage.MESSAGE__DATA_REPRESENTATION_SECTION:
				return dataRepresentationSection != null && !dataRepresentationSection.isEmpty();
			case SecondEditionPackage.MESSAGE__BIT_MAP_SECTION:
				return bitMapSection != null && !bitMapSection.isEmpty();
			case SecondEditionPackage.MESSAGE__DATA_SECTION:
				return dataSection != null && !dataSection.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (startOffset: "); //$NON-NLS-1$
		result.append(startOffset);
		result.append(", endOffset: "); //$NON-NLS-1$
		result.append(endOffset);
		result.append(')');
		return result.toString();
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#buildIndicatorSection(long, long, byte, long, byte)
	 */
	@Override
	public void buildIndicatorSection(long startOffset, long endOffset, byte edition, long messageLength, byte discipline) {

		if(indicatorSection == null)
		{
			indicatorSection = SectionsFactory.eINSTANCE.createIndicatorSection();
		}

		indicatorSection.setStartOffset(startOffset);
		indicatorSection.setEndOffset(endOffset);
		indicatorSection.setDiscipline(discipline);
		indicatorSection.setGribEditionNumber(edition);
		indicatorSection.setMessageLength(messageLength);
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#buildIdentificationSection(long, long, int, byte[])
	 */
	@Override
	public void buildIdentificationSection(long startOffset, long endOffset, int length, byte[] binarySection) {

		if(identificationSection == null)
		{
			identificationSection = SectionsFactory.eINSTANCE.createIdentificationSection();
		}
		
		identificationSection.setStartOffset(startOffset);
		identificationSection.setEndOffset(endOffset);
		identificationSection.initialise(ByteBuffer.wrap(binarySection));
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#addLocalUseSection(long, long, int, byte[])
	 */
	@Override
	public void addLocalUseSection(long startOffset, long endOffset, int length, byte[] binarySection) {
		LocalUseSection sectionToAdd = SectionsFactory.eINSTANCE.createLocalUseSection();
		sectionToAdd.setStartOffset(startOffset);
		sectionToAdd.setEndOffset(endOffset);
		sectionToAdd.setLength(length);
		sectionToAdd.initialise(ByteBuffer.wrap(binarySection));
		localUseSection.add(sectionToAdd);
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#addGridDefinitionSection(long, long, int, byte[])
	 */
	@Override
	public void addGridDefinitionSection(long startOffset, long endOffset, int length, byte[] binarySection) throws MessageException {
		
		if(gridDefinitionSection == null)
		{
			gridDefinitionSection = new EObjectContainmentEList<>(GridDefinitionSection.class, this, SectionsPackage.GRID_DEFINITION_SECTION);
		}
		
		GridDefinitionSection sectionToAdd = SectionsFactory.eINSTANCE.createGridDefinitionSection();
		sectionToAdd.setStartOffset(startOffset);
		sectionToAdd.setEndOffset(endOffset);
		sectionToAdd.setLength(length);
		try {
			sectionToAdd.initialise(ByteBuffer.wrap(binarySection));
		} catch (SectionException e) {
			throw new MessageException(e.getMessage());
		}
		gridDefinitionSection.add(sectionToAdd);
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#addProductDefinitionSection(long, long, int, byte[])
	 */
	@Override
	public void addProductDefinitionSection(long startOffset, long endOffset, int length, byte[] binarySection) throws MessageException {
		
		if(productDefinitionSection == null)
		{
			productDefinitionSection = new EObjectContainmentEList<>(ProductDefinitionSection.class, this, SectionsPackage.PRODUCT_DEFINITION_SECTION);
		}
		
		ProductDefinitionSection sectionToAdd = SectionsFactory.eINSTANCE.createProductDefinitionSection();
		sectionToAdd.setStartOffset(startOffset);
		sectionToAdd.setEndOffset(endOffset);
		sectionToAdd.setLength(length);
		try {
			sectionToAdd.initialise(ByteBuffer.wrap(binarySection));
		} catch (SectionException e) {
			throw new MessageException(e.getMessage());
		}
		productDefinitionSection.add(sectionToAdd);
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#addDataRepresentationSection(long, long, int, byte[])
	 */
	@Override
	public void addDataRepresentationSection(long startOffset, long endOffset, int length, byte[] binarySection) throws MessageException {
		
		if(dataRepresentationSection == null)
		{
			dataRepresentationSection = new EObjectContainmentEList<>(DataRepresentationSection.class, this, SectionsPackage.DATA_REPRESENTATION_SECTION);
		}
		
		DataRepresentationSection sectionToAdd = SectionsFactory.eINSTANCE.createDataRepresentationSection();
		sectionToAdd.setStartOffset(startOffset);
		sectionToAdd.setEndOffset(endOffset);
		sectionToAdd.setLength(length);
		try {
			sectionToAdd.initialise(ByteBuffer.wrap(binarySection));
		} catch (SectionException e) {
			throw new MessageException(e.getMessage());
		}
		dataRepresentationSection.add(sectionToAdd);
	}

	/* (non-Javadoc)
	 * @see org.mro.grib.model.files.secondEdition.Message#addBitMapSection(long, long, int, byte[])
	 */
	@Override
	public void addBitMapSection(long startOffset, long endOffset, int length, byte[] binarySection) {
		
		if(bitMapSection == null)
		{
			bitMapSection = new EObjectContainmentEList<>(BitMapSection.class, this, SectionsPackage.BIT_MAP_SECTION);
		}
		
		BitMapSection sectionToAdd = SectionsFactory.eINSTANCE.createBitMapSection();
		sectionToAdd.setStartOffset(startOffset);
		sectionToAdd.setEndOffset(endOffset);
		sectionToAdd.setLength(length);
		sectionToAdd.initialise(ByteBuffer.wrap(binarySection));
		bitMapSection.add(sectionToAdd);
	}

	@Override
	public void addDataSection(long startOffset, long endOffset, int length, byte[] binarySection) {
		
		if(dataSection == null)
		{
			dataSection = new EObjectContainmentEList<>(DataSection.class, this, SectionsPackage.DATA_SECTION);
		}
		
		DataSection sectionToAdd = SectionsFactory.eINSTANCE.createDataSection();
		sectionToAdd.setStartOffset(startOffset);
		sectionToAdd.setEndOffset(endOffset);
		sectionToAdd.setLength(length);
		sectionToAdd.initialise(ByteBuffer.wrap(binarySection));
		dataSection.add(sectionToAdd);
	}

} //MessageImpl
